package com.ruoyi.web.controller.resource;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.resource.domain.SysBusinessResourceImage;
import com.ruoyi.resource.service.ISysBusinessResourceImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片资源Controller
 *
 * @author ruoyi
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/resource/image")
public class SysBusinessResourceImageController extends BaseController
{
    @Autowired
    private ISysBusinessResourceImageService sysBusinessResourceImageService;

    /**
     * 查询图片资源列表
     */
    @PreAuthorize("@ss.hasPermi('resource:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessResourceImage sysBusinessResourceImage)
    {
        startPage();
        List<SysBusinessResourceImage> list = sysBusinessResourceImageService.selectSysBusinessResourceImageList(sysBusinessResourceImage);
        return getDataTable(list);
    }

    /**
     * 导出图片资源列表
     */
    @PreAuthorize("@ss.hasPermi('resource:image:export')")
    @Log(title = "图片资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessResourceImage sysBusinessResourceImage)
    {
        List<SysBusinessResourceImage> list = sysBusinessResourceImageService.selectSysBusinessResourceImageList(sysBusinessResourceImage);
        ExcelUtil<SysBusinessResourceImage> util = new ExcelUtil<SysBusinessResourceImage>(SysBusinessResourceImage.class);
        util.exportExcel(response, list, "图片资源数据");
    }

    /**
     * 获取图片资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:image:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(sysBusinessResourceImageService.selectSysBusinessResourceImageByImageId(imageId));
    }

    /**
     * 新增图片资源
     */
    @PreAuthorize("@ss.hasPermi('resource:image:add')")
    @Log(title = "图片资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessResourceImage sysBusinessResourceImage)
    {
        return toAjax(sysBusinessResourceImageService.insertSysBusinessResourceImage(sysBusinessResourceImage));
    }

    /**
     * 修改图片资源
     */
    @PreAuthorize("@ss.hasPermi('resource:image:edit')")
    @Log(title = "图片资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessResourceImage sysBusinessResourceImage)
    {
        return toAjax(sysBusinessResourceImageService.updateSysBusinessResourceImage(sysBusinessResourceImage));
    }

    /**
     * 删除图片资源
     */
    @PreAuthorize("@ss.hasPermi('resource:image:remove')")
    @Log(title = "图片资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(sysBusinessResourceImageService.deleteSysBusinessResourceImageByImageIds(imageIds));
    }
}
